package open.witype.filetiper.fragment.file;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import open.witype.filetiper.R;
import open.witype.filetiper.activity.home.HomeActivity;
import open.witype.filetiper.fragment.file.adapter.RecyclerViewAdapter;
import open.witype.filetiper.fragment.file.loader.FileLoader;
import open.witype.filetiper.custom.DividerItemDecoration;
import open.witype.filetiper.custom.DragRecyclerView;
import open.witype.filetiper.fragment.BaseFragment;
import open.witype.filetiper.activity.home.interf.OnItemClickListener;
import open.witype.filetiper.model.FileItemBean;

/**
 * Created by Typer on 2015/5/22 0022.
 * 文件浏览Fragment
 */
public class FileFragment extends BaseFragment {

    public static final String TAG = "FileFragment";

    public static final String PATH = "path";

    public String path;

    public OnItemClickListener itemClickListener;

    private RecyclerViewAdapter adapter;

    /**
     * 实例化FileFragent
     * @param path 路劲
     * @return 实例对象
     */
    public static FileFragment newInstance(String path){
        FileFragment fragment = new FileFragment();
        Bundle bundle = new Bundle();
        bundle.putString(PATH, path);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        path = bundle.getString(PATH);
        root = inflater.inflate(R.layout.fragment_filelist,null);
        init();
        return root;
    }

    public void init(){
        DragRecyclerView recyclerView = (DragRecyclerView)root.findViewById(R.id.recycler);
        recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(itemClickListener);
    }

    public void setRecyclerAdapter(List<FileItemBean> fileItemBeans,Context context){
        adapter = new RecyclerViewAdapter(context);
        adapter.setDatas(fileItemBeans);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.itemClickListener = ((HomeActivity)activity).itemClickListener;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

}
